package fnic.prehand.esagent.activity_measure;

import java.util.List;

import fnic.prehand.common.AgentConfig;
import fnic.prehand.common.BlockQueueService;


public class ActiveLocalQueueRiver implements Runnable{
	private BlockQueueService queueinstance;
//	WorkerThread worker = new WorkerThread();
	PhoneAgent phoneAgent;
	public ActiveLocalQueueRiver(String idx, String type, String ctlurl, String skurl, BlockQueueService queue){
//		String ctrlURL = "http://" + config.getCtrlDBIp() + ":" + config.getCtrlDBPort()+ "/es/mobileindexdesc";
		phoneAgent = new PhoneAgent(idx, type, ctlurl, skurl);
		queueinstance = queue;
	}
	
	public void run() {
		// TODO Auto-generated method stub
		while(true){
			//延迟500毫秒
			List<String> items = queueinstance.getInQueueItems();
			for(String item : items){
				phoneAgent.atomProcess(item);
			}
			
			if(items.size() == 0){
				phoneAgent.processBulkIfNeeded(true);
			}
		}
	}
}
